#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QButtonGroup>
#include <QComboBox>
#include <QFontComboBox>
#include <QGraphicsView>
#include <QMainWindow>
#include <QToolBox>
#include <QToolButton>
#include <QDebug>
#include <QTimer>

#include "projectmanager.h"

#include "SampleDeviceDialog.h"
#include "newprojectdialog.h"

#include "diagram/arrow.h"
#include "diagram/diagramitem.h"
#include "diagram/diagramscene.h"
#include "diagram/diagramtextitem.h"
#include "TwoProgressTableWidget.h"
#include "DeviceChannelTableWidget.h"

#include "charts/mainwidget.h"
#include "devicechannel.h"

#include "Art_DAQ.h"

#define MAX_CHANNEL_COUNT 8

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

protected:
    void resizeEvent(QResizeEvent *) override;
    bool eventFilter(QObject *object, QEvent *event) override;

private slots:
    void on_NewProjectAction_triggered();

    void on_OpenFileAction_triggered();

    void on_DefalutLayoutAction_triggered();

    void on_FlowDesignLayoutAction_triggered();

    void on_FlowRunLayouAction_triggered();

    void on_EditChartaction_triggered();

    void on_EditChart2Action_triggered();

    void on_EditChart3Action_triggered();

public:
    static MainWindow*          instance();

private:
    static MainWindow*          _instance;

    QTimer*                     m_showTimer;

    void UpdateChannelData(int channelno,double value);

    TwoProgressTableWidget *tableWidget;

    DeviceChannelTableWidget *deviceChannelTableWidget;

signals:
    void SendInformation(float64*);

private:
    void slotShowTimer();

    int             m_nIndex;

public:
    static void SendDataMessage(){
        MainWindow::instance()->SendDataMessage_();
    }

    void SendDataMessage_(){
        //UpdateChannelData(0,m_float64SampleData[0]);

        //emit SendInformation(m_float64SampleData);
        //qDebug() << "Send One New Message!";
    }

private:
    void InitProjectDockWidget();
    //初始化表格
    void initTable();
    void CreateFlowChartEditorActions();
    void CreateFlowChartEditorToolBox();
    void CreateFlowChartEditorMenus();
    QWidget *CreateCellWidget(const QString &text, DiagramItem::DiagramType type);
    QWidget *CreateBackgroundCellWidget(const QString &text, const QString &image);

    void CreateToolBars();

public:
    //移除并隐藏所有dock
    void removeAllDock();
    //显示dock窗口
    void showDock(const QList<int> &index = QList<int>());
    //初始化

private:
    QList<QDockWidget *> m_docks; ///< 记录所有dockWidget的指针

private:
    DiagramScene *scene;
    QGraphicsView *view;
    QAction *m_ExitAction;
    QAction *m_AddAction;
    QAction *m_DeleteAction;

    QAction *m_ToFrontAction;
    QAction *m_SendBackAction;
    QAction *m_AboutAction;

    QMenu *fileMenu;
    QMenu *itemMenu;
    QMenu *aboutMenu;

    QToolBar *m_FlowChartEditToolBar;
    QComboBox *m_FontSizeCombo;
    QFontComboBox *m_FontCombo;

    QButtonGroup *m_ButtonGroup;
    QButtonGroup *m_BackgroundButtonGroup;
    QButtonGroup *m_BPMNButtonGroup;

public:
    int TestNET8814Z();

private:
    int32       error = 0;
    TaskHandle  m_hTaskHandle;
    char        errBuff[2048];
    float64     m_float64SampleData[MAX_CHANNEL_COUNT * 1000];

private:
    Ui::MainWindow *ui;

    ProjectManager *m_pProjectManager;

    QToolBox *toolBox;

private:
    MainWidget *m_pChartMainWidget;

private:
    QVector<DeviceChannel*>        m_vecDeviceChannels;
};
#endif // MAINWINDOW_H
